--
-- PostgreSQL database dump
--

-- Started on 2008-06-25 14:04:21 CEST

SET client_encoding = 'UTF8';
SET check_function_bodies = false;
SET client_min_messages = warning;

--
-- TOC entry 1623 (class 1262 OID 33278)
-- Name: explica; Type: DATABASE; Schema: -; Owner: usuario01
--

CREATE DATABASE explica WITH TEMPLATE = template0 ENCODING = 'UTF8';


ALTER DATABASE explica OWNER TO usuario01;

\connect explica

SET client_encoding = 'UTF8';
SET check_function_bodies = false;
SET client_min_messages = warning;

--
-- TOC entry 1624 (class 0 OID 0)
-- Dependencies: 4
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres
--

COMMENT ON SCHEMA public IS 'Standard public schema';


--
-- TOC entry 286 (class 2612 OID 41533)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: 
--

CREATE PROCEDURAL LANGUAGE plpgsql;


SET search_path = public, pg_catalog;

--
-- TOC entry 17 (class 1255 OID 41539)
-- Dependencies: 4 286
-- Name: DELETE_EXT_FIELD_VALUES(numeric, character varying); Type: FUNCTION; Schema: public; Owner: usuario01
--

CREATE FUNCTION "DELETE_EXT_FIELD_VALUES"(numeric, character varying) RETURNS integer
    AS $_$

  DECLARE ID_ITEM ALIAS FOR $1;
  DECLARE COD_EXT_TABLE ALIAS FOR $2;


  DECLARE v_qry VARCHAR(2000) := ' ';
          v_cont INTEGER := 0;
	  v_tmp INTEGER;

  BEGIN
	-- Build the delete query for values of string type extension fields
        v_qry := 'DELETE FROM "ExtFieldStringValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of string type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;

	-- Build the delete query for values of numeric type extension fields
        v_qry := 'DELETE FROM "ExtFieldNumberValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of numeric type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;

	-- Build the delete query for values of date type extension fields
        v_qry := 'DELETE FROM "ExtFieldDateValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of date type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;

	-- Build the delete query for values of boolean type extension fields
        v_qry := 'DELETE FROM "ExtFieldBooleanValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of boolean type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;

	-- Build the delete query for values of long type extension fields
        v_qry := 'DELETE FROM "ExtFieldLongValue" WHERE "idValue"= ' || ID_ITEM || ' AND "idExtField" IN ' || 
		'(SELECT "idExtField" FROM "ExtFieldDefinition" f, "ExtTableDefinition" t WHERE t."idExtTable" = f."idExtTable" ' ||
		'AND t."codExtTable" = ' || quote_literal(COD_EXT_TABLE) || ');';

	-- Run the delete query for values of long type extension fields
	EXECUTE v_qry;

	-- Get the number of rows affected by the delete query
	GET DIAGNOSTICS v_tmp = ROW_COUNT;

	-- Add the number of affected rows to the total sum
	v_cont := v_cont + v_tmp;


        RETURN v_cont;

  END;
  $_$
    LANGUAGE plpgsql;


ALTER FUNCTION public."DELETE_EXT_FIELD_VALUES"(numeric, character varying) OWNER TO usuario01;

--
-- TOC entry 1626 (class 0 OID 0)
-- Dependencies: 17
-- Name: FUNCTION "DELETE_EXT_FIELD_VALUES"(numeric, character varying); Type: COMMENT; Schema: public; Owner: usuario01
--

COMMENT ON FUNCTION "DELETE_EXT_FIELD_VALUES"(numeric, character varying) IS '  --
  -- Function: DELETE_EXT_FIELD_VALUES
  --
  -- Action: Delete all the extension values defined for an extended item.
  --
  -- In Parameters: Extended Item id and extension table code.
  --
  -- Out Parameters: None.
  --
  -- Return: NUMBER with the number of registries affected.
  --
  -- Exception: There is no catching mechanism for exceptions so if anyone
  -- is raised, it will be propagated.';


SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1239 (class 1259 OID 41651)
-- Dependencies: 4
-- Name: AppArea; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "AppArea" (
    "idArea" character varying(5) NOT NULL,
    description character varying(255) NOT NULL
);


ALTER TABLE public."AppArea" OWNER TO "admin";

--
-- TOC entry 1230 (class 1259 OID 41564)
-- Dependencies: 1574 4
-- Name: AppResource; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "AppResource" (
    "idResource" numeric NOT NULL,
    "codResource" character varying(50) NOT NULL,
    description character varying(100) NOT NULL,
    path character varying(250) NOT NULL,
    version bigint DEFAULT 0,
    "idArea" character varying
);


ALTER TABLE public."AppResource" OWNER TO "admin";

--
-- TOC entry 1234 (class 1259 OID 41630)
-- Dependencies: 1579 4
-- Name: BarcodeType; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "BarcodeType" (
    "idBarcodeType" numeric NOT NULL,
    description character varying NOT NULL,
    version bigint DEFAULT 0
);


ALTER TABLE public."BarcodeType" OWNER TO "admin";

--
-- TOC entry 1226 (class 1259 OID 33380)
-- Dependencies: 1573 4
-- Name: ExtFieldBooleanValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldBooleanValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value boolean,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldBooleanValue" OWNER TO "admin";

--
-- TOC entry 1225 (class 1259 OID 33373)
-- Dependencies: 1572 4
-- Name: ExtFieldDateValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldDateValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value timestamp without time zone,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldDateValue" OWNER TO "admin";

--
-- TOC entry 1221 (class 1259 OID 33340)
-- Dependencies: 1568 4
-- Name: ExtFieldDefinition; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldDefinition" (
    "idExtField" numeric NOT NULL,
    "idExtTable" numeric NOT NULL,
    "fieldType" numeric NOT NULL,
    "fieldLength" numeric(6,2),
    "fieldDescription" character varying(100),
    nullable boolean,
    historizable boolean,
    "codExtField" character varying(20) NOT NULL,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldDefinition" OWNER TO "admin";

--
-- TOC entry 1223 (class 1259 OID 33359)
-- Dependencies: 1570 4
-- Name: ExtFieldLongValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldLongValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value oid,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldLongValue" OWNER TO "admin";

--
-- TOC entry 1224 (class 1259 OID 33366)
-- Dependencies: 1571 4
-- Name: ExtFieldNumberValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldNumberValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value numeric,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldNumberValue" OWNER TO "admin";

--
-- TOC entry 1222 (class 1259 OID 33352)
-- Dependencies: 1569 4
-- Name: ExtFieldStringValue; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtFieldStringValue" (
    "idExtField" numeric NOT NULL,
    "idValue" numeric NOT NULL,
    value character varying,
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtFieldStringValue" OWNER TO "admin";

--
-- TOC entry 1220 (class 1259 OID 33333)
-- Dependencies: 1567 4
-- Name: ExtTableDefinition; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ExtTableDefinition" (
    "idExtTable" numeric NOT NULL,
    "idFieldName" character varying(50) NOT NULL,
    "codExtTable" character varying(20) NOT NULL,
    "tableDescription" character varying(100),
    version bigint DEFAULT 0
);


ALTER TABLE public."ExtTableDefinition" OWNER TO "admin";

--
-- TOC entry 1241 (class 1259 OID 41685)
-- Dependencies: 1580 4
-- Name: Image; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "Image" (
    "idImage" numeric NOT NULL,
    path character varying NOT NULL,
    version bigint DEFAULT 0
);


ALTER TABLE public."Image" OWNER TO "admin";

--
-- TOC entry 1627 (class 0 OID 0)
-- Dependencies: 1241
-- Name: TABLE "Image"; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE "Image" IS 'Tabla para guardar las imágenes utilizadas en la aplicación, como por ejemplo imágenes de productos, etc.
Almacena la ruta (en el servidor) del fichero de imagen.';


--
-- TOC entry 1231 (class 1259 OID 41572)
-- Dependencies: 1575 1576 4
-- Name: Product; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "Product" (
    "idProduct" numeric NOT NULL,
    reference character varying NOT NULL,
    description character varying(256) NOT NULL,
    barcode character varying NOT NULL,
    "idGroup" numeric NOT NULL,
    price numeric(12,2) NOT NULL,
    "idVat" numeric NOT NULL,
    version bigint DEFAULT 0,
    "averageCost" numeric(12,2),
    "allowNoStock" boolean DEFAULT false,
    "idBarcodeType" numeric NOT NULL,
    "trData" bytea
);


ALTER TABLE public."Product" OWNER TO "admin";

--
-- TOC entry 1233 (class 1259 OID 41606)
-- Dependencies: 1578 4
-- Name: ProductGroup; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ProductGroup" (
    "idGroup" numeric NOT NULL,
    description character varying(256) NOT NULL,
    version bigint DEFAULT 0
);


ALTER TABLE public."ProductGroup" OWNER TO "admin";

--
-- TOC entry 1242 (class 1259 OID 41700)
-- Dependencies: 4
-- Name: ProductImage; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "ProductImage" (
    "idProduct" numeric NOT NULL,
    "idImage" numeric NOT NULL
);


ALTER TABLE public."ProductImage" OWNER TO "admin";

--
-- TOC entry 1240 (class 1259 OID 41669)
-- Dependencies: 1310 4
-- Name: VW_APP_AREAS; Type: VIEW; Schema: public; Owner: usuario01
--

CREATE VIEW "VW_APP_AREAS" AS
    SELECT a."idArea", a.description AS "areaDescripction", r."idResource" AS "idModule", r."codResource" AS "codModule", r.description AS "moduleDescription", r.path AS "modulePath", r.version AS "moduleVersion" FROM "AppArea" a, "AppResource" r WHERE ((a."idArea")::text = (r."idArea")::text) ORDER BY a."idArea", r."idResource";


ALTER TABLE public."VW_APP_AREAS" OWNER TO usuario01;

--
-- TOC entry 1229 (class 1259 OID 41487)
-- Dependencies: 1309 4
-- Name: VW_EXT_ITEM_VALUES; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW "VW_EXT_ITEM_VALUES" AS
    ((((SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", v.value AS "strVal", NULL::numeric AS "numVal", NULL::timestamp with time zone AS "datVal", NULL::boolean AS "booVal", NULL::oid AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldStringValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", v.value, 14, 15, 16, 17) UNION (SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", NULL::text AS "strVal", v.value AS "numVal", NULL::timestamp with time zone AS "datVal", NULL::boolean AS "booVal", NULL::oid AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldNumberValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", 13, v.value, 15, 16, 17)) UNION (SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", NULL::text AS "strVal", NULL::numeric AS "numVal", v.value AS "datVal", NULL::boolean AS "booVal", NULL::oid AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldDateValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", 13, 14, v.value, 16, 17)) UNION (SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", NULL::text AS "strVal", NULL::numeric AS "numVal", NULL::timestamp with time zone AS "datVal", v.value AS "booVal", NULL::oid AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldBooleanValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", 13, 14, 15, v.value, 17)) UNION (SELECT DISTINCT t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", NULL::text AS "strVal", NULL::numeric AS "numVal", NULL::timestamp with time zone AS "datVal", NULL::boolean AS "booVal", v.value AS "lonVal" FROM "ExtTableDefinition" t, "ExtFieldDefinition" f, "ExtFieldLongValue" v WHERE ((t."idExtTable" = f."idExtTable") AND (f."idExtField" = v."idExtField")) ORDER BY t."idExtTable", t."codExtTable", t."idFieldName", t."tableDescription", f."idExtField", f."codExtField", f."fieldType", f."fieldLength", f."fieldDescription", f.nullable, f.historizable, v."idValue", 13, 14, 15, 16, v.value);


ALTER TABLE public."VW_EXT_ITEM_VALUES" OWNER TO "admin";

--
-- TOC entry 1232 (class 1259 OID 41583)
-- Dependencies: 1577 4
-- Name: VatType; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "VatType" (
    "idVat" numeric NOT NULL,
    description character varying(256) NOT NULL,
    "taxPercentage" numeric(5,2) NOT NULL,
    "recEquiPercentage" numeric(5,2),
    version bigint DEFAULT 0
);


ALTER TABLE public."VatType" OWNER TO "admin";

--
-- TOC entry 1238 (class 1259 OID 41649)
-- Dependencies: 4
-- Name: barcodetype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE barcodetype_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.barcodetype_id_seq OWNER TO "admin";

--
-- TOC entry 1227 (class 1259 OID 33387)
-- Dependencies: 4
-- Name: extfield_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE extfield_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.extfield_id_seq OWNER TO "admin";

--
-- TOC entry 1228 (class 1259 OID 33389)
-- Dependencies: 4
-- Name: exttable_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE exttable_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.exttable_id_seq OWNER TO "admin";

--
-- TOC entry 1243 (class 1259 OID 43100)
-- Dependencies: 4
-- Name: image_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE image_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.image_id_seq OWNER TO "admin";

--
-- TOC entry 1236 (class 1259 OID 41645)
-- Dependencies: 4
-- Name: product_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE product_id_seq
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.product_id_seq OWNER TO "admin";

--
-- TOC entry 1235 (class 1259 OID 41643)
-- Dependencies: 4
-- Name: productgroup_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE productgroup_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.productgroup_id_seq OWNER TO "admin";

--
-- TOC entry 1237 (class 1259 OID 41647)
-- Dependencies: 4
-- Name: vattype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE vattype_id_seq
    START WITH 1
    INCREMENT BY 1
    MAXVALUE 100000000
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.vattype_id_seq OWNER TO "admin";

--
-- TOC entry 1610 (class 2606 OID 41654)
-- Dependencies: 1239 1239
-- Name: AppArea_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "AppArea"
    ADD CONSTRAINT "AppArea_pkey" PRIMARY KEY ("idArea");


--
-- TOC entry 1596 (class 2606 OID 41571)
-- Dependencies: 1230 1230
-- Name: AppResource_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "AppResource"
    ADD CONSTRAINT "AppResource_pkey" PRIMARY KEY ("idResource");


--
-- TOC entry 1608 (class 2606 OID 41637)
-- Dependencies: 1234 1234
-- Name: BarcodeType_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "BarcodeType"
    ADD CONSTRAINT "BarcodeType_pkey" PRIMARY KEY ("idBarcodeType");


--
-- TOC entry 1594 (class 2606 OID 33386)
-- Dependencies: 1226 1226 1226
-- Name: ExtFieldBooleanValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldBooleanValue"
    ADD CONSTRAINT "ExtFieldBooleanValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1592 (class 2606 OID 33379)
-- Dependencies: 1225 1225 1225
-- Name: ExtFieldDateValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldDateValue"
    ADD CONSTRAINT "ExtFieldDateValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1584 (class 2606 OID 33346)
-- Dependencies: 1221 1221
-- Name: ExtFieldDefinition_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldDefinition"
    ADD CONSTRAINT "ExtFieldDefinition_pkey" PRIMARY KEY ("idExtField");


--
-- TOC entry 1588 (class 2606 OID 33365)
-- Dependencies: 1223 1223 1223
-- Name: ExtFieldLongValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldLongValue"
    ADD CONSTRAINT "ExtFieldLongValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1590 (class 2606 OID 33372)
-- Dependencies: 1224 1224 1224
-- Name: ExtFieldNumberValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldNumberValue"
    ADD CONSTRAINT "ExtFieldNumberValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1586 (class 2606 OID 33358)
-- Dependencies: 1222 1222 1222
-- Name: ExtFieldStringValue_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtFieldStringValue"
    ADD CONSTRAINT "ExtFieldStringValue_pkey" PRIMARY KEY ("idExtField", "idValue");


--
-- TOC entry 1582 (class 2606 OID 33339)
-- Dependencies: 1220 1220
-- Name: ExtTableDefinition_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ExtTableDefinition"
    ADD CONSTRAINT "ExtTableDefinition_pkey" PRIMARY KEY ("idExtTable");


--
-- TOC entry 1612 (class 2606 OID 41718)
-- Dependencies: 1241 1241
-- Name: Image_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "Image"
    ADD CONSTRAINT "Image_pkey" PRIMARY KEY ("idImage");


--
-- TOC entry 1598 (class 2606 OID 41582)
-- Dependencies: 1231 1231
-- Name: ProductBarcode_unique; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "ProductBarcode_unique" UNIQUE (barcode);


--
-- TOC entry 1606 (class 2606 OID 41613)
-- Dependencies: 1233 1233
-- Name: ProductGroup_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ProductGroup"
    ADD CONSTRAINT "ProductGroup_pkey" PRIMARY KEY ("idGroup");


--
-- TOC entry 1614 (class 2606 OID 41706)
-- Dependencies: 1242 1242 1242
-- Name: ProductImage_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "ProductImage"
    ADD CONSTRAINT "ProductImage_pkey" PRIMARY KEY ("idProduct", "idImage");


--
-- TOC entry 1600 (class 2606 OID 41580)
-- Dependencies: 1231 1231
-- Name: ProductReference_unique; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "ProductReference_unique" UNIQUE (reference);


--
-- TOC entry 1602 (class 2606 OID 41578)
-- Dependencies: 1231 1231
-- Name: Product_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "Product_pkey" PRIMARY KEY ("idProduct");


--
-- TOC entry 1604 (class 2606 OID 41600)
-- Dependencies: 1232 1232
-- Name: VatType_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "VatType"
    ADD CONSTRAINT "VatType_pkey" PRIMARY KEY ("idVat");


--
-- TOC entry 1616 (class 2606 OID 41655)
-- Dependencies: 1230 1239 1609
-- Name: AppResourceAppArea_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "AppResource"
    ADD CONSTRAINT "AppResourceAppArea_fkey" FOREIGN KEY ("idArea") REFERENCES "AppArea"("idArea");


--
-- TOC entry 1615 (class 2606 OID 33347)
-- Dependencies: 1221 1220 1581
-- Name: ExtFieldDefinition_idExtTable_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ExtFieldDefinition"
    ADD CONSTRAINT "ExtFieldDefinition_idExtTable_fkey" FOREIGN KEY ("idExtTable") REFERENCES "ExtTableDefinition"("idExtTable");


--
-- TOC entry 1621 (class 2606 OID 41724)
-- Dependencies: 1242 1241 1611
-- Name: ProductImage_idImage_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ProductImage"
    ADD CONSTRAINT "ProductImage_idImage_fkey" FOREIGN KEY ("idImage") REFERENCES "Image"("idImage");


--
-- TOC entry 1620 (class 2606 OID 41707)
-- Dependencies: 1242 1231 1601
-- Name: ProductImage_idProduct_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "ProductImage"
    ADD CONSTRAINT "ProductImage_idProduct_fkey" FOREIGN KEY ("idProduct") REFERENCES "Product"("idProduct");


--
-- TOC entry 1619 (class 2606 OID 41638)
-- Dependencies: 1231 1234 1607
-- Name: Product_idBarcodeType_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "Product_idBarcodeType_fkey" FOREIGN KEY ("idBarcodeType") REFERENCES "BarcodeType"("idBarcodeType");


--
-- TOC entry 1618 (class 2606 OID 41614)
-- Dependencies: 1231 1233 1605
-- Name: Product_idGroup_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "Product_idGroup_fkey" FOREIGN KEY ("idGroup") REFERENCES "ProductGroup"("idGroup");


--
-- TOC entry 1617 (class 2606 OID 41601)
-- Dependencies: 1231 1232 1603
-- Name: Product_idVat_fkey; Type: FK CONSTRAINT; Schema: public; Owner: admin
--

ALTER TABLE ONLY "Product"
    ADD CONSTRAINT "Product_idVat_fkey" FOREIGN KEY ("idVat") REFERENCES "VatType"("idVat");


--
-- TOC entry 1625 (class 0 OID 0)
-- Dependencies: 4
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2008-06-25 14:04:21 CEST

--
-- PostgreSQL database dump complete
--

